package com.planet.handel.handels;


import com.planet.common.domain.TaskInfo;
import com.planet.common.enums.ChannelType;
import org.springframework.beans.factory.annotation.Autowired;

import javax.annotation.PostConstruct;

public abstract class Handler {

    /**
     * 标识渠道的Code
     * 子类初始化的时候指定
     */
    protected Integer channelCode;

    @Autowired
    private HandlerHolder handlerHolder;

    /**
     * 初始化渠道与Handler的映射关系
     */
    @PostConstruct
    private void init() {
//        for (ChannelType channelType : ChannelType.values()) {
//            handlerHolder.putHandler(channelType.getCode(), this);
//        }
        handlerHolder.putHandler(channelCode, this);
    }

    public void doHandler(TaskInfo taskInfo) {
        handler(taskInfo);
    }
    /**
     * 统一处理的handler接口
     @@ -14,7 +35,6 @@ public interface Handler {
      * @param taskInfo
     * @return
     */
    public abstract void handler(TaskInfo taskInfo);

}
